//
//  ViewController.m
//  28-UIViewAnimation
//
//  Created by Snow on 16/8/22.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ViewController.h"
#import "UIView+Frame.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *animationView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //关键帧动画//
    //1> 开始动画设置
    //参数1: 动画标识
    //参数2: 上下文
    self.animationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    _animationView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_animationView];
    [UIView beginAnimations:nil context:NULL];
    //2> 设置动画曲线-如何进行动画, 跟速度有关
    [UIView setAnimationCurve:3];
//    UIViewAnimationCurveEaseInOut,         // slow at beginning and end
//    UIViewAnimationCurveEaseIn,            // slow at beginning
//    UIViewAnimationCurveEaseOut,           // slow at end
//    UIViewAnimationCurveLinear,
    //3> 设置动画持续时间
    [UIView setAnimationDuration:3];
    //4.重复次数
//    [UIView setAnimationRepeatCount:2.5];
    //设置往返动画, 一个来回算一次
//    [UIView setAnimationRepeatAutoreverses:YES];
    [UIView setAnimationsEnabled:YES];//忽略动画过程, 直接动画出结果
    //5 动画延时 延时10秒
    //    [UIView setAnimationDelay:10];
    //    [UIView setAnimationStartDate:[NSDate dateWithTimeIntervalSinceNow:10]];

    //6> 动画改变
//    _animationView.x_width = self.view.x_width;
//    _animationView.x_height = self.view.x_height;
    //7> 动画的代理, 不签订代理, 代理方法不执行(默认为不签订)
    [UIView setAnimationDelegate:self];
    //将要开始
    [UIView setAnimationWillStartSelector:@selector(animationWillStart:context:)];
    //将要结束
    [UIView setAnimationWillStartSelector:@selector(animationDidStop:finished:)];
    
    //x> 结束动画设置, 执行该动画
    [UIView commitAnimations];
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        
//        for (int i = 0; i < 101; i++) {
//            _animationView.x_x = i;
//        }
//    });
    
    //2.UIViewAnimationBlock
    //(1).UIViewBlockAnimation
    //参数1: 持续时间
    //参数2: block 需要执行的动画效果
//    [UIView animateWithDuration:5 animations:^{
//        _animationView.x_x = 300;
//    }];
    //(2).完成后, 需要执行的操作
//    [UIView animateWithDuration:5 animations:^{
//        
//    } completion:^(BOOL finished) {
//        NSLog(@"动画完成后需要执行的效果");
//    }];
    
    //(3)
    //参数2:延迟
    //参数3:选项枚举, 按位枚举 1<< 0, 多选
    [UIView animateWithDuration:5 delay:3 options:UIViewAnimationOptionRepeat animations:^{
        _animationView.x_x = 300;
    } completion:^(BOOL finished) {
        
    }];
}
- (void)animationWillStart:(NSString *)animationID context:(void *)context
{}
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
